 /*
 * @description: 抽奖活动(参与用户)
 * @Author: along
 * @Date: 2020-03-04
 * @Last Modified by: along
 * @Last Modified time: 2020-03-04
 */
<template>
    <div class="container luckDrawUser">
        <div class="__tab">
            <p class="__tab_title">参与用户</p>
            <div
                class="__tab_right"
            >
                <p class="__tab_desc">参与人数:</p>
                <p class="__tab_number">{{ info.try_user_count }}人</p>
                <p class="__tab_desc">参与次数:</p>
                <p class="__tab_number">{{ info.try_count }}次</p>
            </div>
        </div>
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">用户信息:</p>
                    <el-input
                        v-model="formData.user_info"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">抽奖时间:</p>
                    <el-date-picker
                        v-model="date"
                        type="datetimerange"
                        :picker-options="pickerOptions()"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        align="right"
                        size="small"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">获奖奖项:</p>
                    <el-input
                        v-model="formData.luck_rank"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">中奖状态:</p>
                    <el-select
                        v-model="formData.luck_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                        :style="{width: '110px'}"
                    >
                        <el-option
                            v-for="item in luckList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <!-- <div class="header-new-box">
                    <p class="header-new-box-title">获奖奖项:</p>
                    <el-select
                        v-model="formData.luck_rank"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in rankList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div> -->
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="handleExportForm()"
                    >
                        导出表单
                    </el-button>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="handleCheckRecord()"
                    >
                        查看中奖记录
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="luckDrawUser"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="student_info.true_name"
                label="姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="student_info.phone"
                label="手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            />
            <el-table-column
                prop="student_info.student_no"
                label="用户编号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="try_time"
                label="抽奖时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.try_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="award_status"
                label="中奖状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.award_status | filterStatus }}
                </template>
            </el-table-column>
            <el-table-column
                prop="item.item_title"
                label="获奖奖项"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="item.title"
                label="获奖奖品"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import { getDate } from '@/assets/js/utils';
import { mapState } from 'vuex';
export default {
    mixins: [back],
    components: {
    },
    data () {
        return {
            no: '',
            formData: {
                user_info: '',
                luck_status: 99,
                luck_rank: ''
            },
            date: '',
            luckList: [{value: 99,label: '全部'},{value: 0,label: '未中奖'},{value: 1,label: '已中奖'}],
            // rankList: [{value: 99,label: '全部'},{value: 1,label: '一等奖'},{value: 2,label: '二等奖'},{value: 3,label: '三等奖'}],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {
        filterStatus (val) {
            if(val === 0) return '未中奖';
            if(val === 1) return '已中奖';
            return '--';
        },
        // filterLuck (val) {
        //     if(val === 1) return '一等奖';
        //     if(val === 2) return '二等奖';
        //     if(val === 3) return '三等奖';
        //     return '--';
        // }
    },
    computed: {
        ...mapState({
            info: state => state.active.info
        })
    },
    watch: {},
    mounted () {
        this.no = this.$route.query && this.$route.query.no ? this.$route.query.no : '';
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '商城'},{title: '抽奖活动', path: '/student/luck-draw-list'},{title: '参与用户'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();

        // 查询info
        if(localStorage.getItem('ZSDX_ACTIVE_INFO')) {
            this.$store.commit('active/CHECK_ACTIVE_INFO');
        }
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/shop_tool%5Clottery%5Cget_try_list', {
                page_id: page || this.page.now_page,
                lottery_no: this.no,
                student_keyword: this.formData.user_info,
                try_start_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[0]))),
                try_end_time: this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[1]))),
                award_status: this.formData.luck_status,
                item_title: this.formData.luck_rank
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 导出表单
         */
        handleExportForm () {
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');

            let url = `${base}/student/shop_tool%5Clottery%5Cexport_try_list?page_id=${this.page.now_page}&lottery_no=${this.no}&student_keyword=${this.formData.user_info}&try_start_time=${this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[0])))}&try_end_time=${this.date === null ? '' : (this.date.length == 0 ? '' : getDate(new Date(this.date[1])))}&award_status=${this.formData.luck_status}&item_title=${this.formData.luck_rank}&__ticket=${ticket}`;

            window.open(url);

        },

        /**
         * @description 查看中奖记录
         */
        handleCheckRecord (row) {
            this.$router.push({
                name: 'luckDrawRecord',
                query: {
                    no: this.no
                }
            });
        },

        /**
         * @description 时间处理
         */
        pickerOptions () {
            return {
                shortcuts : [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            };
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .__tab {
            height: 68px;
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            align-items: center;
            border-bottom: 1px rgba(240, 242, 245, 1) solid;
            margin-bottom: 14px;
            .__tab_title {
                color: rgba(51, 51, 51, 1);
                font-size: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                &::before {
                    content: '';
                    position: absolute;
                    width: 3px;
                    height: 20px;
                    background: rgba(24, 144, 255, 1);
                    top: -1px;
                    left: -8px;
                }
            }
            .__tab_right {
                display: flex;
                .__tab_desc {
                    color: rgba(51, 51, 51, 1);
                    font-size: 14px;
                }
                .__tab_number {
                    color: rgba(245, 158, 51, 1);
                    font-size: 14px;
                    margin-left: 4px;
                    margin-right: 12px;
                }
            }
        }
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 24px;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                // margin-bottom: 10px;
                margin-top: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .zsdx_button_luck {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
</style>
<style lang="less">
    .luckDrawUser{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-button+.el-button {
            margin-left: 0px !important;
        }
        .zsdx_button_luck {
            .el-button {
                padding: 3px;
            }
        }
    }
</style>
